local zhuhuanh = fk.CreateSkill {
  name = "zhuhuanh",
}

zhuhuanh:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#zhuhuanh-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = player:getCardIds("h")
    player:showCards(cards)
    if player.dead then return end
    cards = table.filter(cards, function (id)
      return table.contains(player:getCardIds("h"), id) and Fk:getCardById(id).trueName == "slash" and not player:prohibitDiscard(id)
    end)
    local n = #cards
    room:throwCard(cards, self.name, player, player)
    if player.dead then return end
    local targets = table.map(room:getOtherPlayers(player, false), Util.IdMapper)
    if #targets == 0 then return end
    local to = room:askForChoosePlayers(player, targets, 1, 1, "#zhuhuanh-choose:::"..n, self.name, false)
    to = room:getPlayerById(to[1])
    local choice = room:askForChoice(to, {"zhuhuanh_damage:::"..n, "zhuhuanh_recover::"..player.id..":"..n}, self.name)
    if choice:startsWith("zhuhuanh_damage") then
      room:damage{
        from = player,
        to = to,
        damage = 1,
        skillName = self.name,
      }
      if not to.dead and not to:isNude() and n > 0 then
        room:askForDiscard(to, n, n, true, self.name, false)
      end
    else
      if player:isWounded() then
        room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name,
        })
      end
      if not player.dead and n > 0 then
        player:drawCards(n, self.name)
      end
    end
  end,
})

return zhuhuanh